#!/usr/bin/env python
# coding: utf-8

# In[2]:


import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
import seaborn as sns
import matplotlib.dates as mdates
import numpy as np # linear algebra
from sklearn.metrics import mean_absolute_error, mean_squared_error
from sklearn.model_selection import train_test_split
import math
from datetime import datetime, date 
import warnings
warnings.filterwarnings('ignore')
from tensorflow import keras
from tensorflow.keras import layers
from keras.models import Sequential
from keras.layers import Dense

print("Setup Complete")


# In[3]:


dam = pd.read_csv("3Dam.csv", encoding= 'cp949')
dam.head()


# In[4]:


dam.columns = ['date', 'water_level', 'rainfall', 'inflow', 'outflow', 'water_level2', 'rainfall2', 'inflow2', 'outflow2','water_level3', 'rainfall3', 'inflow3', 'outflow3']
dam.head()


# Seomjin River Dam: 'water_level', 'rainfall', 'inflow', 'outflow'/ Juam Dam: 'water_level2', 'rainfall2', 'inflow2', 'outflow2'/ Juam Control Dam: 'water_level3', 'rainfall3', 'inflow3', 'outflow3'

# In[94]:


dam['inflow'] = pd.to_numeric(dam['inflow'],errors='coerce')
dam['outflow'] = pd.to_numeric(dam['outflow'],errors='coerce')
dam['inflow2'] = pd.to_numeric(dam['inflow2'],errors='coerce')
dam['outflow2'] = pd.to_numeric(dam['outflow2'],errors='coerce')
dam['inflow3'] = pd.to_numeric(dam['inflow3'],errors='coerce')
dam['outflow3'] = pd.to_numeric(dam['outflow3'],errors='coerce')


# In[95]:


print(dam.isnull().sum())


# In[96]:


dam = dam.dropna(axis=0)


# In[97]:


print(dam.isnull().sum())


# In[98]:


dam.describe()


# In[99]:


dam=dam[dam['water_level']>100]
dam=dam[dam['rainfall']>=0]
dam=dam[dam['inflow']>=0]
dam=dam[dam['outflow']>=0]

dam=dam[dam['rainfall2']>=0]
dam=dam[dam['inflow2']>=0]
dam=dam[dam['outflow2']>=0]

dam=dam[dam['water_level3']>0]
dam=dam[dam['rainfall3']>=0]
dam=dam[dam['inflow3']>=0]
dam=dam[dam['outflow3']>=0]


# In[11]:


dam.describe()


# In[13]:


dam = dam.reset_index(drop=True)


# In[14]:


dam["date"] = pd.to_datetime(dam["date"])
dam.index = dam["date"]


# In[15]:


dam


# # Fig10

# In[52]:


plt.rcParams['figure.figsize'] = (29, 10)
plt.rcParams['font.size'] = 18

fig, ax1 = plt.subplots()
ax1.plot(dam.water_level, label='Obs', color='black', linewidth=5)
ax1.set_ylabel('Water Level (EL.m)', fontsize=48)
ax1.tick_params(axis='x', labelsize=43) #rotation=10,
ax1.tick_params(axis='y', labelsize=42)
ax1.grid(True)

ax2 = ax1.twinx()
ax2.plot(dam.outflow, label='Outflow', color='r', linewidth=5)
ax2.set_ylabel('Outflow (m3/sec)', color='r', fontsize=48)
ax2.tick_params(axis='y', labelsize=42, colors='r')

ax1.set_title('S dam\n', fontsize=28)

ax1.set_zorder(ax1.get_zorder() + 10)
ax1.patch.set_visible(False)

ax1.spines['bottom'].set_linewidth(2)
ax1.spines['top'].set_linewidth(2)
ax1.spines['left'].set_linewidth(2)
ax1.spines['right'].set_linewidth(2)

# Get legend handles and labels from both axes
handles1, labels1 = ax1.get_legend_handles_labels()
handles2, labels2 = ax2.get_legend_handles_labels()

# Combine the handles and labels from both axes
all_handles = handles1 + handles2
all_labels = labels1 + labels2
    
ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
plt.show()


# In[43]:


plt.rcParams['figure.figsize'] = (29, 10)
plt.rcParams['font.size'] = 18

fig, ax1 = plt.subplots()
ax1.plot(dam.rainfall, label='Rainfall', color='b', linewidth=5)
ax1.set_ylabel('Rainfall (mm)',color='b', fontsize=48)
ax1.tick_params(axis='x', labelsize=40) 
ax1.tick_params(axis='y', colors='b', labelsize=42)

ax1.grid(True)
ax1.set_title('S dam\n', fontsize=28)

ax1.spines['bottom'].set_linewidth(2)
ax1.spines['top'].set_linewidth(2)
ax1.spines['left'].set_linewidth(2)
ax1.spines['right'].set_linewidth(2)

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
plt.show()


# In[53]:


plt.rcParams['figure.figsize'] = (29, 10)
plt.rcParams['font.size'] = 18

fig, ax1 = plt.subplots()
ax1.plot(dam.water_level2, label='Obs', color='black', linewidth=5)
ax1.set_ylabel('Water Level (EL.m)', fontsize=48)
ax1.tick_params(axis='x', labelsize=43) 
ax1.tick_params(axis='y', labelsize=42)
ax1.grid(True)

ax2 = ax1.twinx()
ax2.plot(dam.outflow2, label='Outflow', color='r', linewidth=5)
ax2.set_ylabel('Outflow (m3/sec)', color='r', fontsize=48)
ax2.tick_params(axis='y', labelsize=42, colors='r')

ax1.set_title('J dam\n', fontsize=28)

ax1.set_zorder(ax1.get_zorder() + 10)
ax1.patch.set_visible(False)

ax1.spines['bottom'].set_linewidth(2)
ax1.spines['top'].set_linewidth(2)
ax1.spines['left'].set_linewidth(2)
ax1.spines['right'].set_linewidth(2)

# Get legend handles and labels from both axes
handles1, labels1 = ax1.get_legend_handles_labels()
handles2, labels2 = ax2.get_legend_handles_labels()

# Combine the handles and labels from both axes
all_handles = handles1 + handles2
all_labels = labels1 + labels2
    
ax1.xaxis.set_major_locator(mdates.YearLocator(base=2)) 
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
plt.show()


# In[45]:


plt.rcParams['figure.figsize'] = (29, 10)
plt.rcParams['font.size'] = 18

fig, ax1 = plt.subplots()
ax1.plot(dam.rainfall2, label='Rainfall', color='b', linewidth=5)
ax1.set_ylabel('Rainfall (mm)',color='b', fontsize=48)
ax1.tick_params(axis='x', labelsize=40) #rotation=10,
ax1.tick_params(axis='y', colors='b', labelsize=42)
ax1.grid(True)
ax1.set_title('J dam\n', fontsize=28)

ax1.spines['bottom'].set_linewidth(2)
ax1.spines['top'].set_linewidth(2)
ax1.spines['left'].set_linewidth(2)
ax1.spines['right'].set_linewidth(2)

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
plt.show()


# In[55]:


plt.rcParams['figure.figsize'] = (29, 10)
plt.rcParams['font.size'] = 18

fig, ax1 = plt.subplots()
ax1.plot(dam.water_level3, label='Obs', color='black', linewidth=5)
ax1.set_ylabel('Water Level (EL.m)', fontsize=48)
ax1.tick_params(axis='x', labelsize=43)
ax1.tick_params(axis='y', labelsize=42)

ax2 = ax1.twinx()
ax2.plot(dam.outflow3, label='Outflow', color='r', linewidth=5)
ax2.set_ylabel('Outflow (m3/sec)', color='r', fontsize=48)
ax2.tick_params(axis='y', labelsize=42, colors='r')

ax1.set_title('J C dam\n', fontsize=28)
ax1.set_zorder(ax1.get_zorder() + 10)
ax1.patch.set_visible(False)

ax1.spines['bottom'].set_linewidth(2)
ax1.spines['top'].set_linewidth(2)
ax1.spines['left'].set_linewidth(2)
ax1.spines['right'].set_linewidth(2)

# Get legend handles and labels from both axes
handles1, labels1 = ax1.get_legend_handles_labels()
handles2, labels2 = ax2.get_legend_handles_labels()

# Combine the handles and labels from both axes
all_handles = handles1 + handles2
all_labels = labels1 + labels2

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
ax1.grid(True)
plt.show()


# In[56]:


plt.rcParams['figure.figsize'] = (29, 10)
plt.rcParams['font.size'] = 18

fig, ax1 = plt.subplots()
ax1.plot(dam.rainfall3, label='Rainfall', color='b', linewidth=5)
ax1.set_ylabel('Rainfall (mm)',color='b', fontsize=48)
ax1.tick_params(axis='x', labelsize=40) #rotation=10,
ax1.tick_params(axis='y', colors='b', labelsize=42)

#ax1.axhline(y=108.5, color='g', linestyle='--', linewidth=3.5) # 추가된 부분
# 그리드 선을 ax1 기준으로 추가
ax1.grid(True)
ax1.set_title('J C dam\n', fontsize=28)

# 그래프 가장자리 굵게 설정
ax1.spines['bottom'].set_linewidth(2)
ax1.spines['top'].set_linewidth(2)
ax1.spines['left'].set_linewidth(2)
ax1.spines['right'].set_linewidth(2)

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  # 2년 간격으로 눈금 설정
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
plt.show()


# # Remove Outlier

# In[100]:


plt.figure(figsize=(25,6))
sns.boxplot(data=dam['outflow'], color='red')
plt.show()


# In[101]:


#remove outlier

Q1 = dam['outflow'].quantile(0.25)
Q3 = dam['outflow'].quantile(0.75)
IQR = Q3 - Q1    #IQR is interquartile range. 

filter = (dam['outflow'] >= Q1 - 1.5 * IQR) & (dam['outflow'] <= Q3 + 1.5 *IQR)
dam = dam.loc[filter]
print(dam['outflow'].describe())
print('\n')
print(dam['outflow'].describe())


# In[102]:


plt.figure(figsize=(25,6))
sns.boxplot(data=dam['outflow'], color='red')
plt.show()


# In[103]:


dam = dam.reset_index(drop=True)


# In[104]:


dam["date"] = pd.to_datetime(dam["date"])
dam.index = dam["date"]


# In[105]:


dam.head()


# # Normalize

# In[106]:


dam


# In[107]:


features = dam[['water_level', 'rainfall', 'inflow', 'outflow', 'water_level2', 'rainfall2', 'inflow2', 'outflow2','water_level3', 'rainfall3', 'inflow3', 'outflow3']]
print(features)


# In[108]:


from sklearn.preprocessing import MinMaxScaler

scaler=MinMaxScaler()
scaler.fit(features)
dam_scaled=scaler.transform(features)

dam_scaled=pd.DataFrame(data=dam_scaled, columns=list(features))
print('feature 최솟값')
print(dam_scaled.min())
print('\n''fearure 최댓값')
print(dam_scaled.max())


# In[109]:


dam['variation'] = 0
for i, idx in enumerate(dam.index):
    dam.loc[idx, 'variation'] = dam_scaled['rainfall'][i]+dam_scaled['inflow'][i]-dam_scaled['outflow'][i]


# In[110]:


dam['variation2'] = 0
for i, idx in enumerate(dam.index):
    dam.loc[idx, 'variation2'] = dam_scaled['rainfall2'][i]+dam_scaled['inflow2'][i]-dam_scaled['outflow2'][i]


# In[111]:


dam['variation3'] = 0
for i, idx in enumerate(dam.index):
    dam.loc[idx, 'variation3'] = dam_scaled['rainfall3'][i]+dam_scaled['inflow3'][i]-dam_scaled['outflow3'][i]


# In[112]:


dam_scaled


# In[113]:


dam = dam.reset_index(drop=True)


# In[114]:


df = dam['variation']
df


# In[115]:


ds_list = []

for i in range(1,len(df)):
    ds = df[i]-df[i-1]
    ds_list.append(ds)
    
ds_dt = pd.DataFrame(ds_list)


# In[116]:


ds_dt.columns = ['ds_dt']
print(ds_dt)


# In[117]:


ds_dt['ds_dt'] = pd.to_numeric(ds_dt['ds_dt'],errors='coerce')
print(ds_dt)


# In[118]:


df2 = dam['variation2']
df2


# In[119]:


ds_list = []

for i in range(1,len(df2)):
    ds = df2[i]-df2[i-1]
    ds_list.append(ds)
    
ds_dt2 = pd.DataFrame(ds_list)


# In[120]:


ds_dt2.columns = ['ds_dt2']
print(ds_dt2)


# In[121]:


ds_dt2['ds_dt2'] = pd.to_numeric(ds_dt2['ds_dt2'],errors='coerce')
print(ds_dt2)


# In[122]:


df3 = dam['variation3']
df3


# In[123]:


ds_list = []

for i in range(1,len(df3)):
    ds = df3[i]-df3[i-1]
    ds_list.append(ds)
    
ds_dt3 = pd.DataFrame(ds_list)


# In[124]:


ds_dt3.columns = ['ds_dt3']
print(ds_dt3)


# In[125]:


ds_dt3['ds_dt3'] = pd.to_numeric(ds_dt3['ds_dt3'],errors='coerce')
print(ds_dt3)


# # Fig11

# In[209]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level']
x= dam_scaled['inflow']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Seomjin river dam\n', fontsize = 23)
plt.xlabel('Inflow', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)
#plt.xlim([-0.2,0.2])
plt.ylim
plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# In[210]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level2']
x= dam_scaled['inflow2']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Juam dam\n', fontsize = 23)
plt.xlabel('Inflow', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)

plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# In[211]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level3']
x= dam_scaled['inflow3']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Juam Control dam\n', fontsize = 23)
plt.xlabel('Inflow', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)

plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# In[212]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level']
x= dam_scaled['rainfall']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Seomjin river dam\n', fontsize = 23)
plt.xlabel('Rainfall', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)

plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# In[213]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level2']
x= dam_scaled['rainfall2']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Juam dam\n', fontsize = 23)
plt.xlabel('Rainfall', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)

plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# In[214]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level3']
x= dam_scaled['rainfall3']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Juam Control dam\n', fontsize = 23)
plt.xlabel('Rainfall', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)

plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# In[215]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level']
x= dam_scaled['outflow']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Seomjin river dam\n', fontsize = 23)
plt.xlabel('Outflow', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)

plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# In[208]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level2']
x= dam_scaled['outflow2']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Juam dam\n', fontsize = 23)
plt.xlabel('Outflow', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)

plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# In[216]:


plt.figure(figsize=(9,6))
y= dam_scaled['water_level3']
x= dam_scaled['outflow3']
plt.scatter(x,y, s=3, alpha = 0.2, c="blue")
plt.title('Juam Control dam\n', fontsize = 23)
plt.xlabel('Outflow', fontsize = 30)
plt.ylabel('Water level', fontsize = 30)

plt.xticks(fontsize =21)
plt.yticks(fontsize =22)
plt.xticks([i / 10 for i in range(int(x.min() * 10), int(x.max() * 10) + 1)])

plt.show()


# # Fig12

# In[40]:


dam_scaled['date']=dam['date']


# In[42]:


dam_scaled


# In[70]:


A=dam_scaled[dam_scaled['outflow']<0.2]
B=dam_scaled[dam_scaled['outflow']>0.2]
B=B[B['outflow']<0.65]


# In[174]:


print(len(A)/len(dam_scaled))
print(len(B)/len(dam_scaled))


# In[175]:


import numpy as np
import seaborn as sns
plt.figure(figsize=(9,7))
stat = "proportion"  
sns.ecdfplot(A['water_level'], stat=stat, lw=4, linestyle = '-', color='r', label='OP1: 53.4%')
sns.ecdfplot(B['water_level'], stat=stat, lw=4, linestyle = '--', color='g', label='OP2: 46.2%')

plt.title('Seomjin River dam', fontsize = 28)
plt.xlabel('Percentage of Maximum Water Level', fontsize = 27)
plt.ylabel('Outflow Density', fontsize = 27)
plt.ylim([0, 1.1])
plt.legend(fontsize=25, loc='upper left')
plt.xticks(fontsize =25)
plt.yticks(fontsize =25)

plt.figure()


# In[165]:


A=dam_scaled[dam_scaled['inflow']<0.15]
print(len(A)/len(dam_scaled))


# In[166]:


import numpy as np
import seaborn as sns
plt.figure(figsize=(9,7))
stat = "proportion"
sns.ecdfplot(A['water_level'], stat=stat, lw=4, linestyle = '-', color='r', label='OP1: 98.6%')

plt.title('Seomjin River dam', fontsize = 28)
plt.xlabel('Percentage of Maximum Water Level', fontsize = 27)
plt.ylabel('Inflow Density', fontsize = 27)
plt.ylim([0, 1.1])
plt.legend(fontsize=25, loc='upper left')
plt.xticks(fontsize =25)
plt.yticks(fontsize =25)

plt.figure()


# In[217]:


A=dam_scaled[dam_scaled['inflow3']<0.15]
print(len(A)/len(dam_scaled))


# In[218]:


import numpy as np
import seaborn as sns
plt.figure(figsize=(9,7))
stat = "proportion"  
sns.ecdfplot(A['water_level3'], stat=stat, lw=4, linestyle = '-', color='r', label='OP1: 99.6%')

plt.title('Juam Control dam', fontsize = 28)
plt.xlabel('Percentage of Maximum Water Level', fontsize = 27)
plt.ylabel('Inflow Density', fontsize = 27)
plt.ylim([0, 1.1])
plt.legend(fontsize=25, loc='upper left')
plt.xticks(fontsize =25)
plt.yticks(fontsize =25)

plt.figure()


# In[170]:


A=dam_scaled[dam_scaled['outflow3']<0.15]
B=dam_scaled[dam_scaled['outflow3']>0.15]
B=B[B['outflow3']<0.4]
C=dam_scaled[dam_scaled['outflow3']>0.4]
C=C[C['outflow3']<0.7]


# In[171]:


print(len(A)/len(dam_scaled))
print(len(B)/len(dam_scaled))
print(len(C)/len(dam_scaled))
print(len(dam_scaled))


# In[172]:


plt.figure(figsize=(9,7))
stat = "proportion"
sns.ecdfplot(A['water_level3'], stat=stat, lw=4, linestyle = '-', color='r', label='OP1: 43%:')
sns.ecdfplot(B['water_level3'], stat=stat, lw=4, linestyle = '--', color='g', label='OP2: 34.9%')
sns.ecdfplot(C['water_level3'], stat=stat, lw=4, linestyle = ':', color='b', label='OP3: 22.1%')

plt.title('Juam Control dam', fontsize = 28)
plt.xlabel('Percentage of Maximum Water Level', fontsize = 27)
plt.ylabel('Outflow Density', fontsize = 27)
plt.ylim([0, 1.1])
plt.legend(fontsize=25, loc='upper left')
plt.xticks(fontsize =25)
plt.yticks(fontsize =25)

plt.figure()


# # Fig13

# In[228]:


dam.index = dam["date"]
dam_scaled.index=dam.index


# In[232]:


dam_scaled


# In[302]:


A=dam_scaled[dam_scaled['outflow']<0.2]

B=dam_scaled[dam_scaled['outflow']>0.2]
B=B[B['outflow']<0.6]


# In[311]:


import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.figure(figsize=(17, 6.5))
ax1 = sns.scatterplot(data=A.water_level, alpha=0.5, s=80, color='g')
ax1.tick_params(axis='x', labelsize=26)
ax1.tick_params(axis='y', colors='g', labelsize=29)
ax1.grid(True)

ax2 = ax1.twinx() 
ax2 = sns.scatterplot(data=A.rainfall, color='b', alpha=0.5, s=80)
ax2.tick_params(axis='y', colors='b', labelsize=29)

ax1.set_ylabel('Water Level', fontsize=33, color='g')
ax2.set_ylabel('Rainfall', fontsize=33, color='b')

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))

plt.show()


# In[312]:


import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.figure(figsize=(17, 6.5))
ax1 = sns.scatterplot(data=B.water_level, alpha=0.5, s=80, color='g')
ax1.tick_params(axis='x', labelsize=26)
ax1.tick_params(axis='y', colors='g', labelsize=29)
ax1.grid(True)

ax2 = ax1.twinx()  
ax2 = sns.scatterplot(data=B.rainfall, color='b', alpha=0.5, s=80)
ax2.tick_params(axis='y', colors='b', labelsize=29)

ax1.set_ylabel('Water Level', fontsize=33, color='g')
ax2.set_ylabel('Rainfall', fontsize=33, color='b')

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))

plt.show()


# In[283]:


A=dam_scaled[dam_scaled['outflow3']<0.04]

B=dam_scaled[dam_scaled['outflow3']>0.18]
B=B[B['outflow3']<0.363]

C=dam_scaled[dam_scaled['outflow3']>0.454]
C=C[C['outflow3']<0.653]

D=dam_scaled[dam_scaled['outflow3']>0.98]
D=D[D['outflow3']<1]


# In[313]:


A=dam_scaled[dam_scaled['outflow3']<0.15]

B=dam_scaled[dam_scaled['outflow3']>0.15]
B=B[B['outflow3']<0.37]

C=dam_scaled[dam_scaled['outflow3']>0.45]
C=C[C['outflow3']<0.65]


# In[314]:


import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.figure(figsize=(17, 6.5))
ax1 = sns.scatterplot(data=A.water_level3, alpha=0.5, s=80, color='g')
ax1.tick_params(axis='x', labelsize=26)
ax1.tick_params(axis='y', colors='g', labelsize=29)
ax1.grid(True)

ax2 = ax1.twinx() 
ax2 = sns.scatterplot(data=A.rainfall3, color='b', alpha=0.5, s=80)
ax2.tick_params(axis='y', colors='b', labelsize=29)

ax1.set_ylabel('Water Level', fontsize=33, color='g')
ax2.set_ylabel('Rainfall', fontsize=33, color='b')

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  # 2년 단위로 눈금 표시
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))

plt.show()


# In[315]:


import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.figure(figsize=(17, 6.5))
ax1 = sns.scatterplot(data=B.water_level3, alpha=0.5, s=80, color='g')
ax1.tick_params(axis='x', labelsize=26)
ax1.tick_params(axis='y', colors='g', labelsize=29)
ax1.grid(True)

ax2 = ax1.twinx()  
ax2 = sns.scatterplot(data=B.rainfall3, color='b', alpha=0.5, s=80)
ax2.tick_params(axis='y', colors='b', labelsize=29)

ax1.set_ylabel('Water Level', fontsize=33, color='g')
ax2.set_ylabel('Rainfall', fontsize=33, color='b')

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2))  
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))

plt.show()


# In[316]:


import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

plt.figure(figsize=(17, 6.5))
ax1 = sns.scatterplot(data=C.water_level3, alpha=0.5, s=80, color='g')
ax1.tick_params(axis='x', labelsize=26)
ax1.tick_params(axis='y', colors='g', labelsize=29)
ax1.grid(True)

ax2 = ax1.twinx()  
ax2 = sns.scatterplot(data=C.rainfall3, color='b', alpha=0.5, s=80)
ax2.tick_params(axis='y', colors='b', labelsize=29)

ax1.set_ylabel('Water Level', fontsize=33, color='g')
ax2.set_ylabel('Rainfall', fontsize=33, color='b')

ax1.xaxis.set_major_locator(mdates.YearLocator(base=2)) 
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))

plt.show()


# In[ ]:




